package sg.edu.nus.iss.umpire.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import sg.edu.nus.iss.umpire.dao.CompetitionDao;
import sg.edu.nus.iss.umpire.domain.Competition;
import sg.edu.nus.iss.umpire.support.NonThreadSafe;

@NonThreadSafe
public class CompetitionDaoImpl extends BaseDaoImpl<Long, Competition>
		implements CompetitionDao {


	public CompetitionDaoImpl(EntityManager em) {
		super(em);
	}

	public Competition findByName(String competitionName) {
		String query = "SELECT FROM " + Competition.class.getName()
				+ " competition where name=:name";
		Query q = em.createQuery(query).setParameter("name", competitionName);
		q.setHint("datanucleus.appengine.datastoreReadConsistency", "EVENTUAL");
		List<Competition> competitionList = (List<Competition>) q
				.getResultList();
		return competitionList != null && 0 != competitionList.size() ? competitionList
				.get(0) : null;
	}
	
}
